[% setvar title Omnibus Structured Exception/Error Handling Mechanism %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<pre>    Omnibus Structured Exception/Error Handling Mechanism</pre>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Tony Olekshy &lt;<a href='mailto:olekshy@avrasoft.com'>olekshy@avrasoft.com</a>&gt;
  Date: 8 Aug 2000
  Last Modified: 1 Oct 2000
  Mailing List: <a href='mailto:perl6-language-errors@perl.org'>perl6-language-errors@perl.org</a>
  Number: 88
  Version: 3
  Status: Frozen</pre>
<a name='NOTES'></a><h1>NOTES</h1>
<pre>    RFC 88 as HTML   <a href='http://www.avrasoft.com/perl6/rfc88.htm' target='_blank'>www.avrasoft.com</a>
    RFC 88 as Text   <a href='http://www.avrasoft.com/perl6/rfc88.txt' target='_blank'>www.avrasoft.com</a>
    RFC 88 as POD    <a href='http://www.avrasoft.com/perl6/rfc88-pod.txt' target='_blank'>www.avrasoft.com</a>

    Perl 5 Try.pm    <a href='http://www.avrasoft.com/perl6/try6-ref5.txt' target='_blank'>www.avrasoft.com</a>
    Regression Test  <a href='http://www.avrasoft.com/perl6/try-tests.htm' target='_blank'>www.avrasoft.com</a></pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>&quot;The Encyclopedia of Software Engineering&quot; [ESE-1994] says (p.847):</p>
<ul>
<li><a name=''></a></li>
<p>Inevitably, no matter how carefully a programmer behaves when writing a
program and no matter how thoroughly its verification is carried out,
errors remain in the program and program execution may result in a
failure.  [...] The programming language may provide a framework for
detecting and then handling faults, so that the program either fails
gracefully or continues to work after some remedial action has been
taken to recover from the error.  Such a linguistic framework is usually
called exception handling.</p>
</ul>
<p>The <i>structured exception handling mechanism</i> described in this RFC
satisfies the following requirements.</p>
<ul>
<li><a name='1'></a>1</li>
<p>It does not, by default, interfere with traditional Perl programming
styles.  When explicitly used, it simply adds functionality to better
support other programming styles, which currently have to undertake
some contortions to get the desired effect.</p>
<p></p>
<li><a name='1'></a>1</li>
<p>It is simple in the cases in which it is commonly used.</p>
<p></p>
<li><a name='1'></a>1</li>
<p>It is capable enough to handle the needs of production applications,
frameworks, and modules, including the ability to hook into the
mechanism itself.</p>
<p></p>
<li><a name='1'></a>1</li>
<p>It is suitable for &quot;error&quot; handling via exceptions.</p>
<p></p>
<li><a name='1'></a>1</li>
<p>It is suitable for light-weight exceptions that may not involve errors
at all.</p>
</ul>
<p>This RFC describes a collection of changes and additions to Perl,
which together support a built-in base class for Exception objects,
and exception/error handling code like this:</p>
<pre>    exception 'Alarm';

    try {
	throw Alarm &quot;a message&quot;, tag =&gt; &quot;ABC.1234&quot;, ... ;
	}

    catch Alarm =&gt; { ... }

    catch Error::DB, Error::IO =&gt; { ... }

    catch $@ =~ /divide by 0/ =&gt; { ... }

    catch { ... }

    finally { ... }</pre>
<p>Any exceptions that are raised within an enclosing try, catch, or
finally block, where the enclosing block can be located anywhere up
the subroutine call stack, are trapped and processed according to
the semantics described in this RFC.</p>
<p>The new built-in Exception base class is designed to be used by Perl
for raising exceptions for failed operators or functions, but this
RFC can be used with the Exception base class whether or not that
happens.</p>
<p>Readers who are not familiar with the technique of using exception
handling to handle errors should refer to the <i><a href='http://search.cpan.org/perldoc?CONVERSION'>CONVERSION</a></i> section
of this document first.</p>
<p>It is not the intent of this RFC to interfere with traditional Perl
scripts; the intent is only to facilitate the availability of a more
controllable, pragmatic, and yet robust mechanism when such is found
to be appropriate.</p>
<ul>
<li><a name='Nothing in this RFC impacts the tradition of simple Perl scripts.'></a>Nothing in this RFC impacts the tradition of simple Perl scripts.</li>
<li><a name='eval {die &quot;Can't foo.&quot;}; print $@; continues to work as before.'></a><code>eval {die &quot;Can't foo.&quot;}; print $@;</code> continues to work as before.</li>
<li><a name='There is no need to use try, throw, catch, or finally at all, if one doesn't want to.'></a>There is no need to use <code>try</code>, <code>throw</code>, <code>catch</code>, or <code>finally</code> at
all, if one doesn't want to.</li>
<li><a name='This RFC does not require core Perl functions to use exceptions for signalling errors.'></a>This RFC does not require core Perl functions to use exceptions
for signalling errors.</li>
</ul>
<a name='DEFINITIONS'></a><h1>DEFINITIONS</h1>
<p><b>raise</b></p>
<ul>
<li><a name=''></a></li>
<p>An exception is raised to begin call-stack unwinding according to the
semantics described herein.  This provides for controlled non-local
flow-control.  This is what <code>die</code> does.</p>
</ul>
<p><b>propagate</b></p>
<ul>
<li><a name=''></a></li>
<p>The passing of an exception up the call stack for further processing
is called propagation.  Raising an exception starts propagation.
Propagation stops when the exception is trapped.</p>
</ul>
<p><b>unwinding</b></p>
<ul>
<li><a name=''></a></li>
<p>The overall process of handling the propagation of an exception,
from the point it is raised until the point it is trapped, is
called unwinding.</p>
</ul>
<p><b>trap</b></p>
<ul>
<li><a name=''></a></li>
<p>The termination of unwinding, for the purpose of attempting further
processing using local flow-control semantics, is called trapping.
This is what <code>eval</code> does, as do <code>try</code>, <code>catch</code>, and <code>finally</code>.</p>
</ul>
<p><b>cleanly caught</b></p>
<ul>
<li><a name=''></a></li>
<p>This means the trapping and handling of an exception did not itself
raise an exception.  Cleanly handling exceptions raised while handling
exceptions is difficult, tedious, and error-prone given only <code>eval</code>.</p>
</ul>
<p><b>exception</b></p>
<ul>
<li><a name=''></a></li>
<p>An exception is a collection of informaton about a particular non-local
goto, captured at raise-time, for use by trap-time handling based on
said informaton.  This is what <code>$@</code> is.  It can be any structured data;
a reference to a blessed hash works well in practice, uses minimal OO
concepts, and can be made to stringify just like the Perl 5 <code>$@</code>.</p>
</ul>
<p><b>error</b></p>
<ul>
<li><a name=''></a></li>
<p>A fuzzy concept, an error is essentially an exception with a negative
connotation.  A traditional definition might be, &quot;an exception raised to
signal an assertion failure that typically indicates the inability of an
algorithm to complete the request it has been given&quot;.  Ultimately,
whether or not an exception is considered to be an error depends on the
trapper, not the raiser.</p>
</ul>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>The most common forms of structured exception handling are straight-
forward.  Here they are:</p>
<pre>  try { ... } catch { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>Invoke the catch block only if the try block raises an exception (aka
dies), otherwise, there is nothing to catch.</p>
<p>Continue unwinding (propagate <code>$@</code>) only if the catch block was invoked
and it raises an exception too.</p>
<p>Otherwise, execute the next statement according to local flow-control,
because either no exception has been raised by either block, or one was
raised in try but it was cleanly caught.</p>
</ul>
<pre>  try { ... } finally { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>Invoke the finally block whether or not the try block raises an
exception.</p>
<p>Continue unwinding (propagate <code>$@</code>) if either the try block or the
finally block raised an exception.</p>
<p>Otherwise, execute the next statement according to local flow control,
because no exception has been raised.</p>
</ul>
<pre>  try { ... }
  catch Exception::Foo =&gt; { ... }
  catch Exception::Bar =&gt; { ... }
  catch                   { ... } # everything else
  finally { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>In this case if the try raises an exception then the first matching
catch is invoked, and then whether or not the try (or any catch) raised
any exception, the finally is invoked.</p>
<p>Once a catch clause matches, subsequent catch clauses are skipped (like
elsif/elsif/else) up to the next finally clause.</p>
<p>This try statement unwinds only if try raises an exception and the
exception's matching catch block raises an exception, or finally raises
an exception.  Otherwise no-one raised an exception, or it was in the
try and it was cleanly caught.</p>
<p>This means that all exceptions propagate unless they are cleanly caught,
just as in Perl 5.  To prevent this, use:</p>
<pre>    try { fragile(); } catch { } # Go on no matter what.</pre>
<p>More complicated constructs should be avoided unless the rules in
<i><a href='#Unwinding Semantics'>&quot;Unwinding Semantics&quot;</a></i> make sense to you and your target audience.</p>
</ul>
<a name='Walkthrough'></a><h2>Walkthrough</h2>
<pre> throw Exception::IO &quot;a message&quot;, tag =&gt; &quot;ABC.1234&quot;, ... ;</pre>
<ul>
<li><a name=''></a></li>
<p>Throw is both a class method and an instance method of the built-in
Exception class.  The indirect object syntax is used to make the
throw imperative.  As a class method, it is syntactic sugar for:</p>
<pre>    die Exception::IO-&gt;new(

	    message =&gt; &quot;a message&quot;, tag =&gt; &quot;ABC.1234&quot;, ...);</pre>
<p>As an instance method it is syntactic sugar for copying over any values
given as arguments, and then effecting <code>die $self</code>.  This allows
<code>throw $@</code> to be used to re-raise exceptions.</p>
<p>Note that a derived class can override its constructor to preprocess the
optional arguments, so that (for example) tags are parsed out of the
message, which allows something like this to work for developers who
prefer it (such as the author):</p>
<pre>	throw MyError &quot;ABC.1234: A message.&quot;;</pre>
<p>This also illustrates why the message is a required argument to the
throw method.  It should not have to be more complicated than that to
raise an exception of a given type with a given annotation, in common
use.  One should not have to always add <code>message =</code>&gt; just for that.</p>
<p>If <code>throw</code> is followed by a &lt;string&gt;, rather than a class, like this:</p>
<pre>	throw &quot;A Message.&quot;, ...;</pre>
<p>it is the equivalent of:</p>
<pre>	throw Exception &quot;A Message.&quot;, ...;</pre>
</ul>
<pre> try { ... } catch &lt;test&gt; =&gt; { ... } finally { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>A try statement starts with a block and is followed by zero or more
catch and/or finally clauses.</p>
<p>The &lt;test&gt; argument of the catch clause is optional, and is described
below.</p>
<p><code>try</code>, <code>catch</code>, and <code>finally</code> blocks should share the same lexical
scope, in the way that <code>while</code> and <code>continue</code> do.  This is so that
variables defined in the <code>try</code> block can be operated on in the other
blocks, which allows one to say:</p>
<pre>	try   { my $fh = open $file }
	finally { $fh and close $fh }</pre>
<p>Note that <code>try</code> is a keyword, not a function.  This is so that a
<code>;</code> is not needed at the end of the last block.  This is because a
try/catch/finally now looks more like an if/elsif/else, which does not
require such a <code>;</code>, than like an eval, which does).</p>
</ul>
<pre> catch { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>Traps all exceptions, according to the unwind semantics described below.</p>
<p>It is a syntax error for a catch all clause like this to be immediately
followed by another catch clause, because that would be dead code that
could never be executed.</p>
<p>Otherwise, it is syntactic sugar for:</p>
<pre>    catch 1 =&gt; { ... }</pre>
<p>To signal failure in a catch block, throw an exception.</p>
</ul>
<pre> catch Exception::DB =&gt; { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>When catch is followed by a class name, the catch block is invoked only
if the current error is an instance of said class.  It is syntactic
sugar for:</p>
<pre>    catch $@-&gt;isa($string) =&gt; { ... }</pre>
</ul>
<pre> catch Exception::DB, Exception::IO =&gt; { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>When catch is followed by a comma-separated list of class names, the
catch block is invoked only if the current is an instance of one of the
given classes.  It is syntactic sugar for:</p>
<pre>    catch grep { $@-&gt;isa($_) } @list =&gt; { ... }</pre>
</ul>
<pre> catch &lt;expr&gt; =&gt; { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>Traps exceptions for which the expression &lt;expr&gt; returns true, when
evaluated at the time the catch clause is attempted, according to
the unwinding semantics described below.</p>
<p>If multiple statements are required to compute the value of the
&lt;expr&gt;, use this form: <code>catch do { a; b } =&gt; { ... }</code></p>
<p>In order to prevent developers from accidentally writing
<code>catch &quot;Exception:DB&quot; =&gt; { ... }</code> (which would be seen as a
test that is always true, while they almost certainly were looking
for a class name), the compiler should detect that special literal
case and issue a compilation warning.</p>
</ul>
<pre> finally { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>Once the try block is entered, every finally block is guaranteed
to be entered before the try statement completes, whether or not
any exceptions have been raised since the try block was entered.</p>
</ul>
<pre> die</pre>
<ul>
<li><a name=''></a></li>
<p>If passed a single argument that isa <code>Exception</code>, raise it as the
new exception and dies in the fashion that Perl 5 does.</p>
<p>Otherwise, the arguments are stringified and joined with <code>''</code> (as
in Perl 5), the resulting string is wrapped up in a new Exception
object (setting the <code>message</code> instance variable to said string),
the original unstringified arguments are saved in a list ref in the
object's <code>data</code> instance variable, and the new <code>Exception</code> object
is raised.</p>
<p>The above guarantees that <code>$@ isa Exception</code> (so developers can
depend on that when writing short conditional catch expressions),
but because of Exception object stringification, in simple scripts
one can still write:</p>
<pre>	open F, $file or die &quot;Can't open $file&quot;;</pre>
<p>When an exception <code>$e</code> is raised, the equivalent of the following
is automatically done, using the variables described below:</p>
<pre>	unshift @@, $@ = $e;</pre>
<p>This provides the mechanism we use to keep track of raised
exceptions while unwinding.</p>
</ul>
<pre> $@ and @@</pre>
<ul>
<li><a name=''></a></li>
<p><code>$@</code> contains the current exception, and <code>@@</code> contains the current
exception stack, as defined above under <code>die</code>.  The <code>unshift</code> rule
guarantees that <code>$@ == $@[0]</code>.</p>
<p><code>$@</code> and <code>@@</code> can <i>only</i> be set by die, which guarantees that <code>$@</code>
and <code>$@[$i]</code> are instances of Exception, as described above.</p>
<p>Unlike eval, try does not start by clearing <code>$@</code>.  The successful
completion of a catch clause clears <code>$@</code> and <code>@@</code>.</p>
<p>Tracking <code>@@</code> information is going to become more important if Perl
starts using exceptions for error handling.  For example, if an <code>open</code>
throws and then a calling DB module throws, and then your UI catches it,
you are (in many cases) going to want to know why the open threw.</p>
</ul>
<pre> eval</pre>
<ul>
<li><a name=''></a></li>
<p>Unchanged from Perl 5.</p>
</ul>
<pre> exception 'Exception::Foo::Bar';</pre>
<ul>
<li><a name=''></a></li>
<p>Makes <code>Exception::Foo::Bar</code> into a class that inherits from the
built-in <code>Exception</code> class, something like:</p>
<pre>    @Exception::Foo::Bar::ISA = 'Exception::Foo';</pre>
</ul>
<pre> exception 'MyError::App::DB::Foo';</pre>
<ul>
<li><a name=''></a></li>
<p>Makes <code>MyError::App::DB::Foo</code> into a class that inherits from the
built-in <code>Exception</code> class.</p>
<p>If the given name matches <code>/::/</code>, something like this happens:</p>
<pre>    @MyError::App::DB::Foo::ISA = 'MyError::App::DB';</pre>
<p>and all non-existent parent classes are automatically created as
inheriting from their parent, or Exception in the tail case.  If
a parent class is found to exist and not inherit from Exception,
a run-time error exception is raised.</p>
<p>If the given name does not match <code>/::/</code> (say it's just <code>Alarm</code>),
this happens instead:</p>
<pre>    @Alarm::ISA = 'Exception';</pre>
<p>This means that every exception class isa Exception, even if
<code>Exception::</code> is not used at the beginning of the class name.</p>
<p>The exception function can also take optional arguments, along the
lines of</p>
<pre>    exception 'Error_DB', isa =&gt; &quot;MyError::App&quot;;</pre>
<p>which results (after error checking) in something like</p>
<pre>    @Error_DB::ISA = 'MyError::App';</pre>
<p>Other options may possibly be given to <code>exception</code> to control things
like the raise-time stack traceback.</p>
</ul>
<a name='Examples'></a><h2>Examples</h2>
<p>The first three of these examples cover the most common uses of try,
catch, and finally.</p>
<pre>  try { my $f = open &quot;foo&quot;; ... } finally { $f and close $f; }</pre>
<ul>
<li><a name=''></a></li>
<p>If the open completed successfully (so defining <code>$f</code>), <code>close $f</code>
is attempted no matter what else happens.</p>
<p>If anything in the try or finally clauses raises an exception, said
exception is propagated after attempting the finally block.  Otherwise
execution continues locally.</p>
<p>This sort of functionality is commonly required, not just with files and
close, but (for example) with objects that don't want to rely on garbage
collection for the invocation of cleanup code.</p>
</ul>
<pre>  try { fragile(); } catch { print &quot;$@\n&quot;; }</pre>
<ul>
<li><a name=''></a></li>
<p>If the try block raises an exception, the catch block is entered.  No
exception is propagated, unless the catch block raises an exception
(because if it doesn't the exception raised by try is considered
&quot;cleanly caught&quot;).</p>
<p>In this example, if <code>fragile()</code> raises an exception it's shown on
<code>STDOUT</code>, and then execution continues normally (unless <code>print</code> raises
an exception).  The stringification method of the exception object is
used to generate the output.  Note that <code>print $@-&gt;show;</code> can be
used to dump the entire exception unwind stack, as described elsewhere
herein.</p>
</ul>
<pre>  try { ... }
  catch Exception::Foo =&gt; { ... }
  finally { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>If the try block raises an <code>Exception::Foo</code> exception then the catch
block is invoked.  Whether or not try or catch raised an exception, the
finally block is invoked.</p>
<p>If try and catch both raised exceptions, or finally raised an exception,
then it is propagated, but if try raised an exception and catch and
finally didn't, then no exception is propagated (because the exception
was cleanly caught).</p>
</ul>
<p>Here's another simple yet quite robust example based on the first two
examples.</p>
<pre>    sub attempt_closure_after_successful_candidate_file_open
    {
	my ($closure, @fileList) = @_; local (*F);
	foreach my $file (@fileList) {
	    try { open F, $file; } catch { next; }
	    try { &amp;$closure(*F); } finally { close F; }
	    return;
	    }
	throw Exception &quot;Can't open any file.&quot;,
	       debug =&gt; @fileList . &quot; tried.&quot;;
	}</pre>
<p>Most developers will usually only find need for cases like those
shown above.  The following examples can be used when circumstances
merit, but they should be avoided by those looking for maximal
simplicity.  Anything can be done with state variables and nested
simple trys, at least until you run off the right of the page or
forget a re-throw.  The following examples are provided for your
convenience, not as a requirement to understanding this RFC or
using its mechanism.</p>
<pre>  try { ... }
  catch Exception::Foo =&gt; { ... }
  catch Exception::Bar =&gt; { ... }
  catch                   { ... }
  finally { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>If the try block raises an exception then: if the first catch matches it
is invoked, if the second catch matches it is invoked, otherwise the
third catch is invoked.</p>
<p>The finally block is entered no matter what happens.</p>
<p>No exception is propagated unless one of the catch blocks raises an
exception, or the finally block does (because otherwise any exception
raised by try is considered to have been &quot;cleanly caught&quot;).</p>
</ul>
<pre>  try { ... } catch $@-&gt;{message} =~ /.../ =&gt; { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>Any exception object instance variable, such as message, tag, or
severity, can be used to test whether or not the exception should be
caught.  The result of the stringification of <code>$@</code> can be similarly
tested.</p>
<p>This also allows one to define a convenience subroutine to make, for
example, the following work:</p>
<pre>	catch not &amp;TooSevere =&gt; { ... }</pre>
</ul>
<pre>  try { ... } catch ref $@ =~ /.../ =&gt; { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>Catches the current exception if has a class name that matches the
given regular expression!</p>
</ul>
<pre>  try { ... } catch grep { $_-&gt;isa(&quot;Foo&quot;) } @@ =&gt; { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>The catch clause is invoked only if any exception on the exception
unwind stack, aka <code>@@</code>, isa Foo.  Note that developers of applications
that need to search the stack a lot can define a simple convenience
subroutine to allow</p>
<pre>	catch AnyException(&quot;Error::IO&quot;) =&gt; { ... }</pre>
<p>which is an excellent example of the utility of the
<code>catch &lt;expr&gt;</code> form.</p>
</ul>
<pre>  try { ... } catch grep { $@-&gt;isa($_) } @list =&gt; { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>Rather that repeating a long list of exceptions that you need to catch
in multiple places, this form allows you to put them in a list.  Again,
in practice, a convenience subroutine would probably be defined to hold
the list and compute the predicate.</p>
</ul>
<pre>  try { ... } catch $@-&gt;isa(&quot;Foo&quot;) &amp;&amp; $@-&gt;CanBar =&gt; { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>Derived exception classes can add new instance variables and methods to
do things like test new predicates.  The above form allows these
predicates to be used with try.  If polymorphism is desired, use</p>
<pre>    catch $@-&gt;can(&quot;CanBar&quot;) &amp;&amp; $@-&gt;CanBar =&gt; { ... }</pre>
</ul>
<pre>  try { my $p = P-&gt;new; my $q = Q-&gt;new; ... }
  finally { $p and $p-&gt;Done; }
  finally { $q and $q-&gt;Done; }</pre>
<ul>
<li><a name=''></a></li>
<p>This construct makes sure that if <code>$q</code> is successfully constructed,
then <code>$q-&gt;Done</code> is invoked even if <code>$p-&gt;Done</code> raises an
exception.  Works for opening and closing a pair of files too.</p>
</ul>
<pre>  try     { TryToFoo; }
  catch   { TryToHandle; }
  finally { TryToCleanUp; }
  catch   { throw Exception &quot;Can't cleanly Foo.&quot;; }</pre>
<ul>
<li><a name=''></a></li>
<p>Unshifts a new exception onto <code>@@</code> if any of the first three blocks
throws, unless successfully handled.  Use of this technique at major API
entry points can result in the availability of better information when
unwinding is eventually caught, like this:</p>
<pre>    UIM.1234: Can't add a new person to the database.
    APP.2345: Can't update Company relationship.
    DBM.3456: Trouble processing SQL UPDATE clause.
    DBM.4567: Unable to write to Locations table.
    IOM.5678: Can't open file &quot;.../locations.ndx&quot;.
    IOM.6789: File &quot;.../locations.ndx&quot; not found.</pre>
<p>The following table shows the details of this construct.
The key is 1 = succeeds, 0 = fails, x = skipped.</p>
<pre> TryTo  TryTo    TryTo   | Throw After Finally
  Foo   Handle  CleanUp  |      Description
 ------------------------+--------------------------------------
   1      x        1     | No.  We did Foo and cleaned up.
   1      x        0     | Yes. We did Foo but didn't clean up.
   0      1        1     | No.  We didn't Foo but did Handle it,
 			 |      and then we cleaned up.
   0      1        0     | Yes. We didn't Foo but did Handle it,
 			 |      but then we didn't clean up.
   0      0        1     | Yes. We didn't Foo and didn't Handle
 			 |      it, even though we did clean up.
   0      0        0     | Yes. We didn't do anything right!</pre>
</ul>
<pre>  try {
      ...
      $avoidCatches_JustUnwind = predicate();
      ...
      }
  catch $avoidCatches_JustUnwind =&gt; { throw $@ }
  catch { ... }
  finally { ... }</pre>
<ul>
<li><a name=''></a></li>
<p>This construction allows a try to dynamically decide to avoid its catch
clauses and just propagate any error that occurs in the try block (after
invoking the finally block).</p>
</ul>
<a name='Syntax'></a><h2>Syntax</h2>
<pre>    &lt;exception&gt; := exception &lt;string&gt; &lt;options&gt; ;

    &lt;throw&gt; := throw &lt;class&gt; &lt;message&gt; &lt;options&gt; ;
             | throw &lt;string&gt; &lt;options&gt; ;
             | throw ;

    &lt;message&gt; := # empty
               | &lt;string&gt;
	       | &lt;string&gt; &lt;options&gt;

    &lt;try&gt; := try &lt;block&gt; &lt;clauses&gt;

    &lt;clauses&gt; := # empty
               | &lt;clause&gt; &lt;clauses&gt;

    &lt;clause&gt; := &lt;catch&gt; | &lt;finally&gt;

    &lt;catch&gt; := catch &lt;block&gt;
	     | catch &lt;classes&gt; &lt;comma&gt; &lt;block&gt;
             | catch &lt;expr&gt; &lt;comma&gt; &lt;block&gt;

    &lt;finally&gt; := finally &lt;block&gt;

    &lt;classes&gt; := &lt;class&gt; | &lt;class&gt; , &lt;classes&gt;

    &lt;class&gt;	# Unquoted name of a class that inherits from the
                # built-in Exception class, such as Exception::Foo.

    &lt;options&gt; := # empty
               | , &lt;string&gt; =&gt; &lt;value&gt;
               | , &lt;string&gt; =&gt; &lt;value&gt; &lt;options&gt;

    &lt;block&gt; := { ... }	# A Perl code block.

    &lt;comma&gt; := , | =&gt;

    &lt;expr&gt;	# A Perl expression which is evaluated when
    		# the relevant clause is processed.

    &lt;string&gt;	# A Perl expression which is evaluated and
    		# stringified.</pre>
<a name='Unwinding Semantics'></a><h2>Unwinding Semantics</h2>
<p>&quot;Computer Architecture, Hardware and Software&quot; [RYK-1989] says (p.347):</p>
<ul>
<li><a name=''></a></li>
<p>Three basic design issues concerning exceptions are (1) whether or not
the exception is permitted to return to the point where the exception is
taken, (2) how the execution context to be used during the the handler's
execution is found, and (3) how the association of an exception handler
with and exception event is established.</p>
</ul>
<p>Perl's behaviour after a <code>die</code> starts call-stack unwinding, as
envisioned by this RFC, is as described by the following rules.
The &quot;current exception&quot; is the value of <code>$@</code>.</p>
<ul>
<li><a name='1'></a>1</li>
<p>Whenever an exception is raised Perl looks for the first enclosing
try/catch/finally block, or eval.  If none is found program shutdown
is initiated.</p>
<p>If a try/catch/finally clause is found Perl traps the exception and
proceeds as per rule 2.</p>
<p>If the exception is trapped by an eval the eval returns locally,
preserving the value of <code>$@</code>, according to the usual Perl 5 rules
(regardless of any outer try/catch/finally clauses).</p>
<p></p>
<li><a name='2'></a>2</li>
<p>The try block's &quot;next&quot; associated trap/catch or finally clause is
processed according to rules 3 and 4.  When there are no more clauses
rule 5 is used.</p>
<p></p>
<li><a name='3'></a>3</li>
<p>If a catch &lt;test&gt; returns true (without itself raising an exception),
its associated catch block is entered.</p>
<p>If the catch block is entered and it completes without itself raising an
exception, the current exception and stack are cleared.  But if a catch
&lt;test&gt; or a block raises an exception, it becomes the current exception,
but it does not propagate out of the try statement (at this point).</p>
<p>If a catch &lt;test&gt; raises an exception or returns true, then whether or
not the catch block raises an exception, any succeeding try/catch
clauses up to the next finally clause are skipped (for the purpose of
the &quot;next&quot; iterator in rule 2).  This makes sequential catches work like
switch/case.</p>
<p>Processing then continues with rule 2.</p>
<p></p>
<li><a name='4'></a>4</li>
<p>When a finally clause is encountered its block is entered.</p>
<p>If the finally block raises an exception it becomes the current
exception, but it does not propagate out of the statement (at this
point).</p>
<p>Processing continues with rule 2.</p>
<p></p>
<li><a name='5'></a>5</li>
<p>After the catch and finally blocks are processed, if there is a current
exception then it is re-raised and propagated as per Rule 1 (beginning
above the current try statement in the call stack).</p>
<p>Otherwise the current exception and stack are cleared, the try statement
completes normally, and Perl continues with the statement after the try
statement.</p>
</ul>
<a name='Built-In Exception Class'></a><h2>Built-In Exception Class</h2>
<p>Exceptions raised by the guts of Perl are envisioned by this RFC to
all be instances of derived classes that inherit from Exception (so
the class hierarchy can be used for exception classification).
This is discussed below under <i><a href='http://search.cpan.org/perldoc?IMPACT'>IMPACT</a></i> + RFC 80.</p>
<p>The built-in Exception class and unwinding functionality described
in this RFC can be used whether or not Perl 6 goes to internal
exceptions.</p>
<p>Instances of the actual (non-subclassed) Exception class itself are
used for simple exceptions, for those cases in which one more or
less just wants to say <code>throw Exception &quot;My message.&quot;</code>, without a
lot of extra tokens, and without getting into higher levels of the
taxonomy of exceptions.</p>
<a name='Instance Variables'></a><h2>Instance Variables</h2>
<p>The built-in Exception class reserves all instance variable and
method names matching <code>/^[_a-z]/</code>.  The following instance
variables are defined.</p>
<p><b><code>message</code></b></p>
<ul>
<li><a name=''></a></li>
<p>This is a description of the exception in language intended for the
&quot;end user&quot;.  Potentially sensitive information should not be included
here.</p>
<p>This instance variable is also used to record the string given when
<code>die &quot;Can't foo.&quot;</code> is used.  Because of stringification (described
below), such a <code>die</code> will result in</p>
<pre>	&quot;$@&quot; =~ /Can't foo\./</pre>
</ul>
<p><b><code>tag</code></b></p>
<ul>
<li><a name=''></a></li>
<p>This is a string which package developers can use to assign a unique
&quot;identifier&quot; to each exception object constructor invocation in their
package.  A package-based namespace control mechanism that helps ensure
the uniqueness of tags is described below, under the <code>tag</code> and
<code>settag</code> methods.  The tag instance variable always contains the fully
qualified tag value.</p>
</ul>
<p><b><code>debug</code></b></p>
<ul>
<li><a name=''></a></li>
<p>This is a place for additional description that is not intended for
the end user (because it is &quot;too technical&quot; or &quot;sensitive&quot;).</p>
<p>For example, in a web application, internal file names might be
considered sensitive information, but you would still like to get
the name of the file that couldn't be opened into the server log.</p>
</ul>
<p><b><code>data</code></b></p>
<ul>
<li><a name=''></a></li>
<p>If the exception is related to some particular object, or the developer
wants to associate other information with this exception, said $data can
be specified via:</p>
<pre>    throw Exception &quot;...&quot;, data =&gt; $data;</pre>
</ul>
<p><b><code>trace</code></b></p>
<ul>
<li><a name=''></a></li>
<p>This is a listref containing a snapshot of the Perl call-stack as at the
time the exception is first raised.  The array contains hashes (one per
call stack level), each containing one key-value pair for each snapshot
value at that level.  Here are some examples:</p>
<pre>	$e-&gt;{trace}-&gt;[0]-&gt;{file}
	$e-&gt;{trace}-&gt;[0]-&gt;{line}
	$e-&gt;{trace}-&gt;[0]-&gt;{package}</pre>
<p>Alternatively, <code>$e-&gt;{trace}</code> could be some sort of snapshot object
thingy.  Similar stuff has been done by the Perl 5 <code>Devel</code> bundle;
perhaps there should be a Perl 6 RFC for it.</p>
<p>The functionality of <code>caller()</code> is used to populate this snapshot data,
but said snapshot has to be taken early and held for possible historic
debugging use, because usually we want to know where we were when things
went wrong, <i>not</i> where we were when we caught that (by which time, the
raise-time stack snapshot data is irrecoverable).</p>
<p>This snapshot data is set up by the <code>snapshot</code> method described below,
so that derived classes that don't want this overhead can override that
method to do nothing.  This can be important to applications that want
to use a large number of light-weight exceptions to implement non-local
success-based flow-control gotos, where the cost of taking and
maintaining the snapshots could prove to be prohibitive, especially
since they would normally never be used.</p>
<p>The snapshot method is an overrideable built-in rather than a stub
though, because in fact in most cases one does want to pay the price for
being able to debug exceptions, because said price is small (in most
cases).</p>
</ul>
<p><b><code>sysmsg</code></b></p>
<ul>
<li><a name=''></a></li>
<p>This a place for the internal exceptions raised by Perl to record
system information, along the lines of <code>$!</code>, <code>$?</code>, and <code>$^E</code>.</p>
<p>Note that the sysmsg instance variable is properly the province
of the various &quot;exceptions for built-ins&quot; proposals, such as RFC 80.
However, if the <code>%@</code> concept described under <i><a href='http://search.cpan.org/perldoc?ISSUES'>ISSUES</a></i> becomes a
part of Perl 6, then <code>sysmsg</code> could just be a reference to a copy
of that hash.</p>
</ul>
<a name='Methods'></a><h2>Methods</h2>
<p>The built-in Exception base class defines the following methods.</p>
<p><b><code>new</code></b></p>
<ul>
<li><a name=''></a></li>
<p>Constructs a new object instance, using its arguments as a hash to
initialize the instance variables by name.</p>
<p>The <code>tag</code> instance variable is treated specially in order to control
the namespace for tags, as follows:</p>
<pre>    $self-&gt;{tag} = $self-&gt;settag($arg{tag});</pre>
</ul>
<p><b><code>throw</code></b></p>
<ul>
<li><a name=''></a></li>
<p>As a class method a new instance is constructed, passing any arguments
to the constructor.  This object becomes <code>$self</code>, and we now have an
instance method.</p>
<p>As an instance method, any arguments are used to update the instance
variables (unless just constructed), and this method effects
<code>die $self</code>.</p>
<p>This method does not return to local flow control (modulo the
<code>on_raise</code> mechanism described below).</p>
</ul>
<p><b><code>overload '&quot;&quot;'</code></b></p>
<ul>
<li><a name=''></a></li>
<p>Stringification produces a concatenation of various Exception object
instance variables and certain delimiters.  The message instance
variable is always to be included.  The details are to be worked out,
but an example would be:</p>
<pre>    ABC.1234 [Warning]: Confirmed but not acknowledged.</pre>
</ul>
<p><b><code>settag</code></b></p>
<ul>
<li><a name=''></a></li>
<p>This method effects whatever operations are performed on the tag
short form given in a throw like this</p>
<pre>    throw Exception &quot;a message&quot;, tag =&gt; &quot;My/Tag/Scheme&quot;</pre>
<p>in order to come up with fully qualified value to be stored in the
tag instance variable.</p>
<p>These operations are properly the province of RFC 80, but the default
could be something like this:</p>
<pre>	$self-&gt;{tag} = (ref $self) .&quot;.&quot;. $_[0];</pre>
<p>or equivalent, as described below.</p>
<p>This would mean that the tags provided to exception constructors need
only be unique across a class, file, or package, which is often
constrained enough to make uniqueness relatively easy in practice.</p>
<p>The example of exception class constructor overriding given later in
this RFC needs to set the tag, while maintaining namespace control,
without knowing the namespace control details, so this method is
provided for that.</p>
<p>Perhaps all this instance variable accessor method stuff can be
cleaned up with other changes to the Perl 6 OO mechanism.</p>
</ul>
<p><b><code>tag</code></b></p>
<ul>
<li><a name=''></a></li>
<p>This method returns true if the object's tag instance variable matches
its argument.  This allows us to easily trap by namespace-controlled
tag, using a form like this:</p>
<pre>	catch $@-&gt;tag(&quot;Foo&quot;) =&gt; { ... }</pre>
<p>The definition of &quot;matches&quot; can be changed, for an exception class
hierarchy, by overriding this method.  The default rule properly is the
province of RFC 80, but it could be something like this (for unique tags
across all throws of the same class):</p>
<pre>	$self-&gt;{tag} eq (ref $self) .&quot;.&quot;. $_[0]</pre>
<p>or for unique tags across all throws in the same package:</p>
<pre>	$self-&gt;{tag} eq (caller(0))[0] .&quot;\t&quot;.$_[0]</pre>
<p>or for unique tags across all throws in the same file:</p>
<pre>	$self-&gt;{tag} eq (caller(0))[1] .&quot;\t&quot;.$_[0]</pre>
</ul>
<p><b><code>show</code></b></p>
<ul>
<li><a name=''></a></li>
<p>This class method and instance method generates a string formatted
version of the exception unwinding stack based on the contents of
<code>@@</code>, stringifying each exception object as it goes.  For example,
<code>print $@-&gt;show</code> produces something like this:</p>
<pre>    UIM.1234: Can't add a new person to database.
    APP.2345: Can't update Company relationship.
    DBM.4567: Unable to write to Company table.
    IOM.5678: Can't open file &quot;.../company.db&quot;.</pre>
<p><code>show</code> takes the following optional parameters.</p>
<p><code>label =&gt; 1</code></p>
<p>If set, the formatted exception stack is annotated with the classes
of the objects therein, as in:</p>
<pre>    Exception::UI: UIM.1234: Can't add a new person to database.
    Exception::DB: APP.2345: Can't update Company relationship.
    Exception::DB: DBM.4567: Unable to write to Company table.
    Exception::IO: IOM.5678: Can't open file &quot;.../company.db&quot;.</pre>
<p><code>trace =&gt; 1</code></p>
<p>If set, the value returned by <code>show</code> includes the Perl stack traceback
using the information from the <i>last</i> exception in the stack, that is
<code>$@[-1]</code>.  Something like this:</p>
<pre>    UIM.1234: Can't add a new person to database.
    APP.2345: Can't update Company relationship.
    DBM.4567: Unable to write to Company table.
    IOM.5678: Can't open file &quot;.../company.db&quot;.

    Try::throw called from test-403.pl[7].
    Try::try called from test-403.pl[9].
    Try::try called from test-403.pl[11].
    Try::try called from test-403.pl[14].</pre>
<p><code>debug =&gt; 1</code></p>
<p>Annotates entries in the unwind stack with the values from their
<code>debug</code> instance variables, if any.  For example:</p>
<pre>    UIM.1234: Can't add a new person to database.
    Debug: Fred Flintstone
    APP.2345: Can't update Company relationship.
    DBM.4567: Unable to write to Company table.
    IOM.5678: Can't open Company file.
    Debug: /foo/bar/company.dat</pre>
<p>Developers who need alternative output can override <code>show</code>.</p>
</ul>
<p><b><code>snapshot</code></b></p>
<ul>
<li><a name=''></a></li>
<p>Used internally to generate the <code>trace</code> instance variable.  Designed
to be overridden in derived classes for performance or extension
purposes.  See the description of the trace instance variable, above.</p>
</ul>
<p><b><code>on_raise</code></b></p>
<ul>
<li><a name=''></a></li>
<p>Derived classes may override this method to attempt to &quot;handle&quot; an
exception or otherwise manipulate it, just before it is raised.  If
<code>on_raise</code> throws or returns true the exception is raised, otherwise it
is not.  An exception can be manipulated or replaced and then propagated
in modified form simply by re-raising it in <code>on_raise</code>.</p>
<p>In the <code>Exception</code> base class this method returns true, so by default
exceptions are always raised.</p>
<p>Unraised throws make no sense for &quot;error&quot; exceptions and are abhorrent
to users of exception handling for error handling, but that's ok because
Exception's <code>on_raise</code> method returns true by default, you have to
actually override a method to change that behaviour, and, well, error
classes could use <code>on_raise</code> for instance variable munging at
propagate-time, as long as they return true.</p>
<p>Nevertheless, other uses for Exception objects may want this
functionality, at least based on the reference and text books
which say that classically, an exception has such a handler hook.</p>
<p>If we do provide it, it need not be used, but if we don't provide it
the functionality cannot otherwise be provided, should it be deemed
desirable for some application.</p>
</ul>
<p><b><code>on_catch</code></b></p>
<ul>
<li><a name=''></a></li>
<p>In the name of symmetric hooks, an <code>on_catch</code> method is called just
before an exception object is cleared from <code>@@</code>.  on_catch may be
overridden by a derived exception class to perform additional debug
logging, or (in fact), to refuse the completion of the catch (by
raising a new exception).</p>
</ul>
<a name='Custom Exceptions'></a><h2>Custom Exceptions</h2>
<p>In addition to the <code>exception 'MyException'</code> mechanism described
above, custom exception and/or error classes can be created along
the following lines:</p>
<pre>    File main.pl:

	use Error::App;

	exception 'Error_DB', isa =&gt; 'Error::App';

	throw Error_DB &quot;ABC.1234: Can't foo.&quot;;

    File Error/App.pm:

	package Error::App;  @Error::App::ISA = 'Error';

	use Error;  # It inherits from Exception.

	sub new
	{
	    my ($C, $msg, %opt) = @_;  $C = ref $C || $C;

	    my $self = $C-&gt;SUPER::new($msg, %opt);

	    $self-&gt;{message} =~ s/^([A-Z]+\/\d+):\s+//
	    and
		$self-&gt;settag($1);

	    return bless($self, $C);
	    }</pre>
<p>Note that the scope of classes like <code>Error::App</code> is is limited to
packages that use it, which presumably want such functionality.</p>
<a name='MOTIVATION'></a><h1>MOTIVATION</h1>
<p>Over the last ten years, the author has come to rely on exception
handling as a relatively robust mechanism for error handling, and
has used exception handling to implement other, non-error related,
non-local flow-control algorithms, in Scheme, C++, Visual Objects,
Delphi, and Perl.  He has developed a relatively complete
implementation of the functionality described herein, in Perl 5, in
the Try.pm module and its associated regression tests [TRY-2000].
A similar version of Try.pm is in use in production applications.</p>
<p>The authors' motivation is to help Perl 6 achieve a relatively robust
exception handling mechanism that is suitable for error handling via
exceptions, is still capable enough to handle the needs of production
programs, and is still suitable for light-weight exceptions that may
not involve errors at all.</p>
<p>&quot;The Encyclopedia of Software Engineering&quot; [ESE-1994] says (p.847):</p>
<ul>
<li><a name=''></a></li>
<p>Among the features offered by programming languages to support exception
handling are the following.</p>
<p></p>
<ul>
<li><a name='1'></a>1</li>
<p>The ability to distinguish the normal control flow from the exception
handling flow to make the structure of the program clear.</p>
<p></p>
<li><a name='2'></a>2</li>
<p>The ability to detect faults as they occur in the program, not only by
explicitly raising an exception but also by implicitly raising it on
account of the run-time environment.  [...] Both kinds of faults should
be handled uniformly.</p>
<p></p>
<li><a name='3'></a>3</li>
<p>The ability to transfer control to a programmer-definable exception
handler when the fault is detected.  The language should specify the
rules by which this detected fault is bound to its corresponding
exception-handling routine.</p>
<p></p>
<li><a name='4'></a>4</li>
<p>The ability to specify how control flows after the exception handler is
executed, i.e., whether one can resume execution from the point at which
it left off, or whether the program should fail.</p>
</ul>
<p>Most early programming languages do not provide specific features for
exception handling, but rather use the normal constructs to implement
it. [...]  Obviously this and other ad hoc methods do not satisfy the
requirements listed above.</p>
</ul>
<p>To this end, new keywords have been deliberately chosen to represent the
new mechanism, in order to make it clear to the developer when the code
is expecting to deal with unwind semantics (rather than with local flow
control).</p>
<p>In addition, the exception handling mechanism propagates exceptions that
are not cleanly caught, which minimizes the chances for the developer to
forget to re-raise uncaught exceptions.  How many of us check for IO
failures after <code>print</code>s?  And if you're writing a simple program you
wouldn't want to have to, but you would want the program to shut down
after a failure even if you don't check.</p>
<p>Remembering to always check all subroutine and functions for failure
return codes can be difficult, since nothing about the form of the call,
in the source code, indicates whether or not a failure return code
should be expected.  And, the exception handling technique not only
works with subroutines and functions, it works with operators too
(which, you will note, is why divide dies on zero denominator: it has
no other way to return an error code).</p>
<p>Although the following code using the new mechanism:</p>
<pre>	try { may_throw_1 }
	catch may_throw_2 =&gt; { may_throw_3 }
	finally { may_throw_4 }</pre>
<p>can be written in Perl 5 like this:</p>
<pre>	eval { may_throw_1 };
	my $exception = $@;
	if ($exception) {
	    my $test = eval { may_throw_2 };
	    $@ and $exception = $@;
	    if ( ! $@ and $test ) {
		eval { may_throw_3 };
		$exception = $@;
		}
	    }
	eval { may_throw_4 };
	($exception ||= $@) and die $exception;</pre>
<p>the opportunity for flow-control errors increases.</p>
<p>Without the functionality provided by the mechanisms described in
this RFC, instead of having a way to be able to write</p>
<pre>    throw Error_DB &quot;ABC.1234: Can't write to table $table.&quot;;</pre>
<p>a developer would be <i>required</i> to write something like</p>
<pre>    throw Exception::Error::App::DB tag =&gt; &quot;ABC.1234&quot;,
	message =&gt; &quot;Can't write to table $table.&quot;;</pre>
<p>The latter has a much lower signal to noise ratio than the former, which
is of <i>significant</i> importance to regular users of exception handling
mechanisms.</p>
<a name='CONVERSION'></a><h1>CONVERSION</h1>
<p>Although the technique of using exception handing for error handling
often seems foreign at first to developers who are not used to it, many
find that it becomes quite natural when four concepts are kept in mind.</p>
<ul>
<li><a name='1'></a>1</li>
<p>Wherever you previously would have <code>return undef</code> or some other
special return code (or a pass-by-reference value), to indicate the
failure of a subroutine or function, instead use <code>throw Exception</code>
(or some fancier form thereof).</p>
<p></p>
<li><a name='2'></a>2</li>
<p>Wherever you previously would have written</p>
<pre>	$x = foo();  defined $x or return undef;</pre>
<p>to propagate an error from a callee back to your caller, you can just
write <code>$x = foo();</code> because unhandled exceptions automatically
propagate.</p>
<p></p>
<li><a name='3'></a>3</li>
<p>Wherever you previously would have written the equivalent of the
following to do something about an error, and then ignore it:</p>
<pre>	$x = foo();
	unless (defined $x) {
	    # do something about error here
	    }</pre>
<p>you can now write</p>
<pre>	try { $x = foo(); }
	catch {
	    # do something about error here
	    }</pre>
<p></p>
<li><a name='4'></a>4</li>
<p>Wherever you previously would have ignored an error in order to allow
you to restore invariants or enforce postconditions, and then used
<code>return undef</code> to propagate the error, like this:</p>
<pre>	open F, ...;
	$x = foo();
	close F;
	defined $x or return undef;</pre>
<p>you can now write</p>
<pre>	open F, ...;
	try     { $x = foo(); }
	finally { close F;    }</pre>
<p>because unhandled exceptions automatically propagate.</p>
</ul>
<p>And, of course, if you don't want to use exception objects just
don't use <code>throw</code>, instead just keep on using <code>die &quot;string&quot;;</code>
as in Perl 5 (because <code>$@</code> stringifies reasonably).</p>
<a name='ISSUES'></a><h1>ISSUES</h1>
<p><b>Perl should be Perl</b></p>
<ul>
<li><a name=''></a></li>
<p>Given that the functionality described in this RFC can be provided
by a Perl 5 module, as implemented in [TRY-2000], the author would
prefer that these capabilities not be made impossible in Perl 6.</p>
</ul>
<p><b>Core Functionality</b></p>
<ul>
<li><a name=''></a></li>
<p>If the guts of Perl 6 are to use exceptions for errors, some
of the stuff in this RFC has to go into the guts of Perl 6 (but
see &quot;Use <code>%@</code> for errors from builtins&quot;, below, for a minimalist
way to do so).</p>
<p>The authors are of the opinion that the public interface to to the
core Perl API should support but not require the use of exceptions
for errors that would set <code>$!</code>, under the control of a
<code>use fatal;</code> or <code>use strict 'fatal';</code> pragma.</p>
</ul>
<p><b>New Keywords</b></p>
<ul>
<li><a name=''></a></li>
<p>RFC 88 only introduces the <code>try</code>, <code>throw</code>, <code>catch</code>, <code>finally</code>,
and <code>exception</code> &quot;keywords&quot;, which are all traditionally related to
exception handling.  And they don't even need to all actually be
keywords, some can be functions (depending on the Perl 6 parser).</p>
<p>New keywords were chosen so that this can be written:</p>
<pre>    try {
	try {
	    try     { ... }
	    finally { ... }
	    }
	catch Exception1 =&gt; { ... }
	catch Exception2 =&gt; { ... }
	}
    catch { print $@, &quot;\n&quot;; }</pre>
<p>instead of cognitively overloading existing keywords and concepts in a
manner like this:</p>
<pre>    eval {
	eval {
	    eval     { ... }
	    continue { ... }
	    }
	else {
	    switch ($@) {
		case /Exception1/ { ... }
		case /Exception2/ { ... }
		else { die $@; }
		}
	    }
	}
    else { print $@, &quot;\n&quot;; }</pre>
<p>because the authors are of the opinion that overloading <code>else</code> and
<code>continue</code> with unwind semantics not traditionally associated with
<code>else</code> and <code>continue</code> can be confusing, especially when intermixed
with local flow-control forms of <code>else</code> and <code>continue</code> (which may
be present in any <code>{ ... }</code> block), or when an <code>else die $@</code>
is forgotten on a <code>switch</code> that needs to re-throw.</p>
<p>Some perl6-language-error discussions have suggested leaving out
the try altogether, as in simply writing <code>{ } else { }</code> to indicate
non-local flow-control at work. Yikes!</p>
<p>The <code>try</code> is not for Perl's sake.  It's for the developer's sake.
It says, watch out, some sort of non-local flow control is going on
here.  It signals intent to deal with action at a distance
(unwinding semantics).  It satisfies the first requirement listed
under <i><a href='http://search.cpan.org/perldoc?MOTIVATION'>MOTIVATION</a></i>.</p>
<p>The <code>throw</code> verb was chosen for raising an exception, because
of its neutral connotation (unlike <code>fail</code> for example), because
exceptions do not necessarily encapsulate a negative.  Similarly,
<code>catch</code> is neutral, unlike <code>try { ... } error { ... }</code>.</p>
</ul>
<p><b>Keyword Names</b></p>
<ul>
<li><a name=''></a></li>
<p>Much discussion was generated on the perl6-language lists about
the selection of keywords for this mechanism.  The minimalist
approach of cognitively overloading existing keywords such as
<code>eval</code>, <code>else</code>, and <code>continue</code> has been discussed above.</p>
<p>The <code>try</code> / <code>throw</code> / <code>catch</code> / <code>finally</code> combination works
well in consideration of the other requirements discussed herein.</p>
<p>For the record, here are some of other words that have either
been used by other programming languages, or suggested on the
mailing lists: raise, always, onException, when, signal, fail,
handle, otherwise, unwind, trap, quit, trip, deal, freak, panic,
cope, punt, ascend, cough, sustain, overrule, and (of course)
<code>longjmp</code>.</p>
</ul>
<p><b>Syntax</b></p>
<ul>
<li><a name=''></a></li>
<p>The comma or <code>=&gt;</code> in a conditional catch clause is required so
the expression can be parsed from the block, in the fashion of Perl
5's parsing of: <code>map &lt;expression&gt; , &lt;list&gt;</code>;
Without the comma, the form <code>catch $foo { ... }</code> could be
a test for <code>$foo</code> or a test for <code>$foo{...}</code> (the hash element).</p>
</ul>
<p><b>Object Model</b></p>
<ul>
<li><a name=''></a></li>
<p>This RFC is written using the basic Perl 5 concept of an object
as a reference to a blessed hash containing instance variable
name-value pairs.  It may need to be modified to account for
any new basic Perl 6 object model.  On the other hand, it makes
minimal demands of any object model.</p>
</ul>
<p><b>Exception Base Class</b></p>
<ul>
<li><a name=''></a></li>
<p>If <code>Exception</code> objects are not to be used for signaling assertion
failures by the guts of Perl 6, this RFC stands alone.  Otherwise,
this RFC delegates the details of the Exception class to RFC 80,
modulo the required functionality described herein (more or less,
that internal exception objects are instances of classes that
inherit from the built-in Exception class).</p>
<p>Either way, the following questions about Exception should be
addressed.</p>
<p></p>
<ul>
<li><a name='How can we subclass Exception and control the class namespace? For example, if the core can use any Exception::Foo, where does one connect non-core Exceptions into the taxonomy? Possibly the core exceptions can derive from Exception::CORE, and everyone else can use the Exception::MyPackage convention.'></a>How can we subclass Exception and control the class namespace?  For
example, if the core can use any <code>Exception::Foo</code>, where does one
connect non-core Exceptions into the taxonomy?  Possibly the core
exceptions can derive from <code>Exception::CORE</code>, and everyone else can
use the <code>Exception::MyPackage</code> convention.</li>
<p></p>
<li><a name='How can we add new instance variables and methods to classes derived from Exception and control those namespaces? Perhaps this will be covered by some new Perl 6 object technology. Otherwise, we will need yet another naming scheme convention.'></a>How can we add new instance variables and methods to classes
derived from Exception and control those namespaces?  Perhaps
this will be covered by some new Perl 6 object technology.
Otherwise, we will need yet another naming scheme convention.</li>
<p></p>
<li><a name='What should the default values be for Exception object instance variables not specified to the constructor? For example, tag could default to file + line number.'></a>What should the default values be for Exception object instance
variables not specified to the constructor?  For example, <code>tag</code>
could default to file + line number.</li>
<p></p>
<li><a name='What assertions should be placed on the instance variables, if any?'></a>What assertions should be placed on the instance variables, if any?</li>
<p></p>
<li><a name='What should stringification return?'></a>What should stringification return?</li>
</ul>
</ul>
<p><b>Lexical Scope</b></p>
<ul>
<li><a name=''></a></li>
<p>The authors would prefer that <code>try</code>, <code>catch</code>, and <code>finally</code> blocks
share the same lexical scope.</p>
<p>If it is not possible to have try, catch, and finally blocks share
lexical scope (due, perhaps, to the vagaries of stack unwinding), this
feature can simply be deleted, and the outer scope can be shared.</p>
<p>One possible shared-scope problem is illustrated by this case:</p>
<pre>    try { fragile(); }
    catch { my $caught = 1; }
    finally { $caught and ... }</pre>
<p>If <code>fragile()</code> doesn't raise an exception then <code>finally</code> is going
to test <code>$caught</code> even though the <code>my</code> statement was never executed.
Will <code>$caught</code> already be allocated and <code>undef</code>?</p>
<p>These matters will have to be referred to the internals experts.</p>
</ul>
<p><b>Mixed Flow Control</b></p>
<ul>
<li><a name=''></a></li>
<p>Some of the reference texts, when discussing exception handling, refer
to the matter that it may be difficult to implement a <code>go to</code> across
an unwinding semantics block, as in:</p>
<pre>	try { open F, $f } catch { next; }</pre>
<p>This matter will have to be referred to the internals experts.  It's ok
if this functionality is not possible, it can always be simulated with
lexical state variables instead.</p>
<p>However, the authors would very much prefer that <code>goto</code>s across
unwinding boundries would DWIM.  If that is not possible, hopefully
some sort of compile-time warning could be produced.</p>
</ul>
<p><b>Use <code>%@</code> for Errors from Builtins</b></p>
<ul>
<li><a name=''></a></li>
<p>RFC 151 proposes a mechanism for consolidating the information provided
by of <code>$@</code>, <code>$!</code>, <code>$?</code>, and <code>$^E</code>.  In the opinion of the author of
RFC 88, merging <code>$@</code> and <code>$!</code> should not be undertaken, because <code>$@</code>
should <i>only</i> be set if an exception is raised.</p>
<p><b><code>%@</code></b> should be used to hold this fault-hash, based on the following
arguments for symmetry.</p>
<pre>        $@    current exception
        @@    current exception stack
        %@    current core fault information

        $@[0]        same as $@

        $@{type}     &quot;IO::File::NotFound&quot;
        $@{message}  &quot;can't find file&quot;
        $@{param}    &quot;/foo/bar/baz.dat&quot;
        $@{child}    $?
        $@{errno}    $!
        $@{os_err}   $^E
        $@{chunk}    That chunk thingy in some msgs.
        $@{file}     Source file name of caller.
        $@{line}     Source line number of caller.</pre>
<p><code>%@</code> should not contain a severity or fatality classification.</p>
<p><i>Every</i> call to a core API function should clear <code>%@</code> if it returns
successfully.</p>
<p>Internally, Perl can use a simple structured data type to hold the
whole canonical <code>%@</code>.  The code that handles reading from <code>%@</code> will
construct it out of the internal data on the fly.</p>
<p>If <code>use fatal;</code> is in scope, then just before returning, each core
API function should do something like: <code>%@ and internal_die %@;</code></p>
<p>The <code>internal_die</code> becomes the one place where a canonical <code>Exception</code>
can be generated to encapsulate <code>%@</code> just before raising an exception,
whether or not the use of such canonical Exceptions is controlled by a
pragma such as <code>use exceptions;</code>.</p>
</ul>
<p><b>retry / resume</b></p>
<ul>
<li><a name=''></a></li>
<p>There has been some discussion on perl6-language-error about the
concept of re-entering <code>try</code> blocks on <code>catch</code> (including the
possibility of using such a mechanism to replace <code>AUTOLOAD</code>).</p>
<p>The author is of the opinion that in order to do this sort of thing
properly one should use continuations, which are being discussed
elsewhere to this RFC.</p>
<p>The intent of this RFC is to provide a simple yet robust exception
handling mechanism that is suitable for error handling, not for
replacing <code>AUTOLOAD</code> or continuations in general.</p>
</ul>
<p><b>always</b></p>
<ul>
<li><a name=''></a></li>
<p>RFC 119 describes a concept that would allow code like this:</p>
<pre>    {
    ...
    &lt;statement&gt; always &lt;block&gt;;
    ...
    }</pre>
<p>With the semantics that the &lt;block&gt; would be invoked when the
lexical scope in which &lt;statement&gt; occurs is exited.  The author
of this RFC thinks that's a fine idea, but that it is orthogonal
to structured exception handling.  The behaviour of <code>always</code> would
be useful whether or not the lexical scope is defined by a simple
local-flow-control block or by a set of try/catch/finally clauses.</p>
</ul>
<p><b>eval</b></p>
<ul>
<li><a name=''></a></li>
<p>The semantics of <code>eval</code> are, &quot;clear <code>$@</code> and don't unwind unless
the user re-dies after the <code>eval</code>&quot;.  The semantics of <code>try</code> are
&quot;unwind after <code>try</code>, unless any raised exception was cleanly and
completely handled, in which case clear <code>$@</code>&quot;.</p>
<p>In the author's opinion, both <code>eval</code> and <code>try</code> should exist in
Perl 6.  This would also mean that the legacy of examples of how to
use <code>eval</code> in Perl will still work.</p>
<p>And, of course, we still need <code>eval $string</code>.</p>
<p>Discussions on perl6-language-errors have shown that some would
prefer the <code>eval { ... }</code> form to be removed from Perl 6,
because having two exception handling methods in Perl could be
confusing to developers.  This would in fact be possible, since
the same effect can be achieved with:</p>
<pre>	try { } catch { } # Clears $@.

	my $e;

	try { ... } catch { $e = $@; }

	# now process $e instead of $@</pre>
<p>On the other hand, <code>eval</code> is a convenient synonym for all that,
given that it already works that way.</p>
</ul>
<p><b><code>catch v/s else + switch</code></b></p>
<ul>
<li><a name=''></a></li>
<p>Some participants in discussions on perl6-language-errors have
expressed the opinion that not only should <code>eval</code> be used instead
of <code>try</code>, but <code>else</code> should be used instead of multiple <code>catch</code>
blocks.  They are of the opinion that an <code>else { switch ... }</code>
should be used to handle multiple catch clauses, as in:</p>
<pre>	eval { ... }
	else {
	    switch ($@) {
		case $@-&gt;isa(&quot;Exception::IO&quot;) { ... }
		case $@-&gt;my_method { ... }
		}
	    }</pre>
<p>This problem with <code>else { switch ... }</code> is: how should the code
implicitly rethrow uncaught exceptions?  Many proponents of this
model think that uncaught exceptions should not be implicitly
rethrown; one suggests that the programmer should <code>undef $@</code> at the
end of <i>every</i> successful &lt;case&gt; block, so that Perl re-raises any
<code>$@</code> still extant at the end of the <code>else</code>.</p>
<p>This RFC allows a <code>switch</code> to be used in a <code>catch { ... }</code>
clause, for cases where that approach would minimize redundant code
in <code>catch &lt;expr</code> { ... }&gt; clauses, but with the mechanism
proposed in this RFC, the switch functionality shown above can be
written like this, while still maintaining the automatic exception
propagation when no cases match:</p>
<pre>	try { ... }
	catch Exception::IO =&gt; { ... }
	catch $@-&gt;my_method =&gt; { ... }</pre>
</ul>
<p><b>Fatal Exceptions</b></p>
<ul>
<li><a name=''></a></li>
<p>Discussions on perl6-language-errors have indicated a desire by some
to be able to easily separate &quot;fatal&quot; exceptions (like divide by zero)
from &quot;non-fatal&quot; exceptions (such as can't open file) if Perl 6 uses
exceptions for error signalling.</p>
<p>The authors are of the opinion that this mechanism and Perl core
exceptions (if any) should not define any sort of <code>severity</code> instance
variable or <code>is_fatal</code> method for the <code>Exception</code> base class, because
no a priori classification of fatality can in general be provided
by the thrower of an exception--that's for the catcher to determine.</p>
<p>Derived Exception class hierarchies can, on the other hand, add
instance data and methods that support a severity concept in their
domain, at which point catching can be made conditional on such a
concept.</p>
</ul>
<p><b>on_raise &amp; on_catch</b></p>
<ul>
<li><a name=''></a></li>
<p>Some participants in discussions on perl6-language-errors currently
prefer that the functionality represented by the <code>on_raise</code> method of
the Exception class not be include at all.  Should that be deemed to be
the case, the <code>on_raise</code> method of the <code>Exception</code> class can be left
out.</p>
<p>It has also been mentioned that we should consider making overriding
of <code>throw</code> impossible, so that <code>throw</code> must <code>die</code>.</p>
<p>The author is of the opinion that these constraints should not be
enforced, because (1) they may provide useful functionality for some
applications, (2) you have to override a method, which is fairly hard to
do by accident, and (3) if this functionality is not built in, there is
no way to simulate it.</p>
<p>Independent of the matter of <code>throw</code> and the hook methods, the
authors agree that there should be <i>no way</i> to disable the raising
of exceptions on some sort of &quot;global&quot; level.  They get through
unless they, or their handling, explicitly say otherwise.</p>
</ul>
<p><b>Stack Snapshot Object</b></p>
<ul>
<li><a name=''></a></li>
<p>This RFC mentions that an exception's <code>trace</code> instance variable could
point to a &quot;stack snapshot&quot; object, rather than to a data structure.  A
mechanism like this is available in the Perl 5 <code>Devel</code> bundle.  If an
RFC for such a snapshot class is added to Perl 6, this RFC should be
reconciled with it.</p>
</ul>
<p><b>Mechanism Hooks</b></p>
<ul>
<li><a name=''></a></li>
<p>In the name of extensibility and debugging, there should be hooks for
callbacks to be invoked when a <code>try</code>, <code>catch</code>, or <code>finally</code> block is
entered or exited, and when a conditional <code>catch</code> is evaluated.  The
callbacks would be passed information about what is happening in the
context they are being called from.</p>
<p>In order to scope the effect of the callbacks (rather than making them
global), it is proposed that the callbacks be specified as options to
the try statement, something like this:</p>
<pre>    try on_catch_enter =&gt; sub { ... },
	on_catch_exit  =&gt; sub { ... },
    {
	...
	}</pre>
<p>The (dynamic, not lexical) scope of these callbacks is from their try
down through all trys nested under it (until overridden at a lower
level).  Nested callbacks should have a way of chaining to callbacks
that were in scope when they come into scope, perhaps by including a
reference to the outer-scope callback as a parameter to the callback.
Basically, they could be kept in &quot;global&quot; variables overridden with
<code>local</code>.</p>
<p>Normally, this mechanism would only be used by an application's
top-level <code>try</code> statement, typically for the purpose of debugging
non-local flow control, or extending the semantics of try.</p>
<p>For example, to refuse to allow any code under the scope of a try
to catch a given exception, one could just say:</p>
<pre>    on_catch_enter =&gt; sub { $@-&gt;isa(&quot;Alarm&quot;) and throw $@ }</pre>
<p>The author would find this functionality very useful in an application
he works with that uses non-error exceptions to implement non-local
success-based flow control in a model- view- controller architecture.</p>
<p>In addition, a <code>snapshots</code> option could be used by the <code>Exception</code>
class <code>snapshot</code> method to control whether or not to take raise-time
call-stack snapshots.</p>
</ul>
<p><b>Mixed-Mode Modules</b></p>
<ul>
<li><a name=''></a></li>
<p>Authors of modules who wish to provide a public API that respects the
current state of <code>use fatal;</code> if such a mechanism is available, can
do so as follows.</p>
<p>Internal to their modules, authors can use lexically scoped
<code>use fatal;</code> to explicitly control whether or not they want
builtins to raise exceptions to signal errors.</p>
<p>Then, if and only if they want to support the other style, and only
for public API subroutines, they do something like one of these:</p>
<p></p>
<ul>
<li><a name='Use return internally, now add support for throw at API:'></a>Use return internally, now add support for throw at API:</li>
<pre> sub Foo
 {
    my $err_code = ... ; # real code goes here

    # Replace the old return $err_code with this:

    return $err_code unless $FATAL_MODE &amp;&amp; $error_code != $ok;

    throw Error::Code &quot;Couldn't Foo.&quot;, code =&gt; $err_code;
    }</pre>
<li><a name='Use throw internally, add support for return at API:'></a>Use throw internally, add support for return at API:</li>
<pre> sub Foo
 {
    try {
	# real code goes here, may execute:

	throw Exception &quot;Couldn't foo.&quot;, code =&gt; $err_code;
	}
    catch !$FATAL_MODE =&gt; { return $@-&gt;{code}; }

    return $ok;
    }</pre>
</ul>
</ul>
<p><b>$SIG{__DIE__}</b></p>
<ul>
<li><a name=''></a></li>
<p>The try, catch, and finally clauses localize and undef <code>$SIG{__DIE__}</code>
before entering their blocks.  This behaviour can be removed if
<code>$SIG{__DIE__}</code> is removed.</p>
<p>If <code>$SIG{__DIE__}</code> is not removed, it should be invoked as at the
phrase &quot;program shutdown is initiated&quot; in Rule 1, not at the time an
exception is raised by <code>die</code>.</p>
<p>If the old functionality is removed, do we want to introduce such
functionality to Rule 1 anyway?</p>
</ul>
<a name='IMPACT'></a><h1>IMPACT</h1>
<p><b>Legacy</b></p>
<ul>
<li><a name=''></a></li>
<p>The only changes in respect of Perl 5 behaviour implied by this RFC are
that (1) <code>$@</code> is now always an <code>Exception</code> object (which stringifies
reasonably), it is now read-only, and it can only be set via <code>die</code>, and
(2) the <code>@@</code> array is now special, and it is now read-only too.</p>
</ul>
<p><b>RFC 63</b>: Exception handling syntax proposal.</p>
<ul>
<li><a name=''></a></li>
<p>The author of RFC 63 (and co-author of RFC 88) has retired RFC 63.</p>
</ul>
<p><b>RFC 70</b>: Allow exception-based error-reporting.</p>
<ul>
<li><a name=''></a></li>
<p>RFC 88 is proposed whether or not faults in the Perl 6 guts are signaled
by exceptions, and whether or not such behaviour is under the control of
a <code>use fatal;</code>.</p>
</ul>
<p><b>RFC 80</b>: Exception objects and classes for built-ins.</p>
<ul>
<li><a name=''></a></li>
<p>The author of RFC 80 is the co-author of RFC 88, and so is aware of the
impact of RFC 88 on RFC 80.</p>
<p>RFC 88 proposes that it's Exception and RFC 80's Exception be the same
thing.  RFC 88 talks about the participation of an Exception in
exception handling.  RFC 80 talks about how to use an Exception object
to signal an exception in Perl's built-in functions and other guts.</p>
</ul>
<p><b>RFC 96</b>: A Base Class for Exception Objects</p>
<ul>
<li><a name=''></a></li>
<p>The author of RFC 96 and RFC 88 has withdrawn RFC 96.</p>
</ul>
<p><b>RFC 119</b>: Object neutral error handling via exceptions.</p>
<ul>
<li><a name=''></a></li>
<p>RFC 119 is a proposal for forms of functionality similar to those
proposed in RFC 88.</p>
</ul>
<p><b>RFC 140</b>: One Should Not Get Away With Ignoring System Call Errors</p>
<ul>
<li><a name=''></a></li>
<p>The functionality in RFC 140 is envisioned for use in cases that don't
want to be running <code>use fatal;</code>.  It is orthogonal to RFC 88 whether
or not running <code>use fatal;</code>.</p>
</ul>
<p><b>RFC-151</b>: Merge <code>$!</code>, <code>$^E</code>, and <code>$@</code></p>
<ul>
<li><a name=''></a></li>
<p>See <i><a href='http://search.cpan.org/perldoc?IMPACT'>IMPACT</a></i> + <i>Use <code>%@</code> for Errors from Builtins</i> for an alternative
the proposal in RFC 151.</p>
</ul>
<a name='ACKNOWLEDGEMENTS'></a><h1>ACKNOWLEDGEMENTS</h1>
<p>This RFC is based on invaluable support on a number of fronts.</p>
<p>This RFC has been refined with the help of (via the perl6 mailing
lists) contributions from Graham Barr, Chaim Frenkel, Jonathan Scott
Duff, Glenn Lindermann, Dave Rolsky, and Corwin Brust.  It has also
benefited from conversations with Jim Hoover.</p>
<p>A slightly different version of the Perl 5 implementation of Try.pm
[TRY-2000] has been used by the staff of Avra Software Lab Inc. for
production code, it has been debated in presentations at the
Software Engineering Research Lab at the University of Alberta, and
it has been discussed on the perl-friends mailing list.  At one
point Try.pm was refined based on the study of Graham Barr's
Error.pm module [GBE-1999].</p>
<a name='AUTHORS'></a><h1>AUTHORS</h1>
<p>Tony Olekshy &lt;<a href='mailto:olekshy@avrasoft.com'>olekshy@avrasoft.com</a>&gt; is the principal author of this
RFC, and is responsible for any errors contained herein.</p>
<p>Peter Scott &lt;<a href='mailto:peter@psdt.com'>peter@psdt.com</a>&gt; is co-author of this RFC, by virtue of
the major contribution he has made hereto.</p>
<p>Where this document refers to the singular author or author's, it
refers to Tony.  Where it refers to co-author or co-author's, it
refers to Peter.  Where it refers to the plural authors or authors',
it refers to both authors.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p><b>ESE-1994</b>: The Encyclopedia of Software Engineering, J.J. Marciniak
(editor), John Wiley &amp; Sons Inc, 1994.  ISBN 0-471-54002-1</p>
<p><b>GBE-1999</b>: Graham Barr's <code>Error.pm</code> module.
<a href='http://search.cpan.org/doc/GBARR/Error-0.13/Error.pm' target='_blank'>search.cpan.org</a></p>
<p>RFC 63: Exception handling syntax</p>
<p>RFC 70: Allow exception-based error-reporting.</p>
<p>RFC 80: Exception objects and classes for builtins</p>
<p>RFC 96: A Base Class for Exception Objects</p>
<p>RFC 119: Object neutral error handling via exceptions</p>
<p>RFC 140: One Should Not Get Away With Ignoring System Call Errors</p>
<p>RFC 151: Merge <code>$!</code>, <code>$^E</code>, <code>$@</code> and <code>$?</code></p>
<p><b>RYK-1989</b>: Computer Architecture, Hardware and Software, R.Y.Kain,
volume 1, Prentice-Hall Inc., 1989.  ISBN 0-13-166752-1</p>
<p><b>TRY-2000</b>: Try.pm, a Perl 5 reference implementation of the
functionality described herein, is available at:
<a href='http://www.avrasoft.com/perl6/try6-ref5.txt' target='_blank'>www.avrasoft.com</a></p>
<a name='REVISIONS'></a><h1>REVISIONS</h1>
<p>Version 1, 2000-08-08</p>
<ul>
<li><a name='Based on Avra Software Lab Inc's Try.pm, redaction 1.1.3.6.'></a>Based on Avra Software Lab Inc's Try.pm, redaction 1.1.3.6.</li>
</ul>
<p>Version 2, 2000-08-23</p>
<ul>
<li><a name='The except keyword is gone, catch takes optional arguments instead.'></a>The <code>except</code> keyword is gone, <code>catch</code> takes optional
arguments instead.</li>
<li><a name='Multiple conditional catch clauses now work like a switch, instead of like a bunch of sequential ifs.'></a>Multiple conditional catch clauses now work like a switch,
instead of like a bunch of sequential ifs.</li>
<li><a name='A built-in Exception-based Error class is no longer defined.'></a>A built-in Exception-based <code>Error</code> class is no longer defined.</li>
<li><a name='Other major restructuring and enhancements throughout.'></a>Other major restructuring and enhancements throughout.</li>
</ul>
<p>Version 3, 2000-09-30</p>
<ul>
<li><a name='You can now throw a string (as well as a class name), in which case the string is wrapped in an Exception object.'></a>You can now throw a string (as well as a class name), in which
case the string is wrapped in an <code>Exception</code> object.</li>
<li><a name='Added to ISSUES: %@, always, Mixed Mode Modules, and Fatal Exceptions.'></a>Added to <i><a href='http://search.cpan.org/perldoc?ISSUES'>ISSUES</a></i>: <i>%@</i>, <i>always</i>, <i>Mixed Mode Modules</i>, and
<i>Fatal Exceptions</i>.</li>
<li><a name='References to [TRY-2000] have been adjusted to reflect the fact that it now contains the new Perl 5 Reference Implementation of RFC 88 (rather than the old Avra version of Try.pm).'></a>References to [TRY-2000] have been adjusted to reflect the fact
that it now contains the new Perl 5 Reference Implementation of
RFC 88 (rather than the old Avra version of Try.pm).</li>
<li><a name='Production formatting has been completed.'></a>Production formatting has been completed.</li>
<li><a name='RFC 88 Frozen.'></a>RFC 88 Frozen.</li>
</ul>
<p><i>End of RFC 88</i></p>
</div>
